package com.burgess.net.topic;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * 非持久Topic消息示例
 * 创建人    BurgessLee
 * 创建时间   2020/5/20
 * 描述
 */
public class NonPersistentMessageConsumer {

    public static void main(String[] args) throws JMSException {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
        Connection connection = activeMQConnectionFactory.createConnection();
        connection.start();

        final Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createTopic("my-non-persistant-topic");
        MessageConsumer consumer = session.createConsumer(destination);
        Message message = consumer.receive();
        while(message != null){
            TextMessage textMessage = (TextMessage)message;
            System.out.println("message: " +textMessage.getText());
            message = consumer.receive(1000L);
        }

    }

}
